home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000121_icon-group-sender _Mon Apr 21 10:51:56 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: from kingfisher.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Mon, 21 Apr 1997 13:23:26 MST
  2. Received: by kingfisher.CS.Arizona.EDU; (5.65v3.2/1.1.8.2/08Nov94-0446PM)
  3.     id AA05136; Mon, 21 Apr 1997 13:23:26 -0700
  4. Date: Mon, 21 Apr 1997 10:51:56 -0700
  5. From: swampler@noao.edu (Steve Wampler)
  6. Subject: Re: Comments on Icon Routine (redux)
  7. To: icon-group@cs.arizona.edu
  8. Message-Id: <swampler-9703211751.AA003815590@orpheus.gemini.edu>
  9. In-Reply-To: <3358C3DD.23EE@airmail.net>
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11. Status: RO
  12. Content-Length: 1273
  13.  
  14.  
  15. In thinking about Steve Graham's problem a bit more, it occurred to me
  16. that some of the tests in the solution can be eliminated.  Here's a
  17. second solution that is a revised version of the earlier one (note that
  18. the procedure ltrim has been improved slightly):
  19.  
  20. procedure main(args)
  21.  
  22.     in  := open(args[1], "r") | stop("Cannot open ", args[1])
  23.     out := open(args[2], "w") | stop("Cannot open ", args[2])
  24.     rmargin := args[3] | 80
  25.  
  26.     while produce(out, read(in), rmargin)
  27.  
  28. end
  29.  
  30. procedure produce(f, s, rm)
  31.  
  32.     ltrim(s) ? {
  33.         if reverse(move(rm)) ? {        # line is too long...
  34.             suffix := reverse(tab(upto(' \t'))) | ""    # ... split it apart
  35.             write(f, reverse(tab(0)))                   # ... print first part
  36.            } then                       #   ... produce the rest of it
  37.             produce(f, suffix||tab(0), rm)
  38.         else                            # line is ok, print it
  39.             write(f, tab(0))
  40.         }
  41.  
  42.     return
  43. end
  44.  
  45. procedure ltrim(s)                      # return trimmed line
  46.     return s ? (tab(many(' ')), tab(0)) | tab(0)
  47. end
  48.  
  49. --
  50. Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
  51. O Sibile, si ergo, fortibus es inero.
  52. Nobile, demis trux.  Demis phulla causan dux.
  53.